package org.ceteca.explica.core.partners;

import java.io.Serializable;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;




/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class RappelTypeOT extends BaseVO implements Serializable {



	private static final long serialVersionUID = 1L;

	
	private long idRappelType;
	private String description;
	private Integer version=new Integer(0);
	private Set<RappelIntervalOT> rappelIntervals;
	

	public RappelTypeOT() {
		super();
	}



	public long getIdRappelType() {
		return idRappelType;
	}



	public void setIdRappelType(long idRappelType) {
		this.idRappelType = idRappelType;
	}



	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setRappelIntervals(Set<RappelIntervalOT> rappelIntervals) {
		this.rappelIntervals = rappelIntervals;
	}



	public Set<RappelIntervalOT> getRappelIntervals() {
		return rappelIntervals;
	}


	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idRappelType == id.longValue();
	}

	

	@Override
	public String toString() {
		StringBuffer result  = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%% RAPPEL TYPE    %%%%%%%%%%%%%%%%%%");
			result.append("\nID RAPPEL TYPE: ");
			result.append(this.idRappelType);
			result.append("\nDESCRIPTION: ");
			result.append(this.description);
			if (getRappelIntervals()!=null)
				result.append("\nRappel Intervals #"+getRappelIntervals().size());
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting RappelTypeOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
		
		
	}


	@Override
	public String getEntityId() {
	
		return InterfacePartners.EXPLICA_ENTITY_RAPPELTYPE_ID;
	}

	@Override
	public long getInternalId() {

		return this.idRappelType;
	}

	@Override
	public String getInternalValue() {

		return this.description;
	}

	public Integer getVersion() {
		return version;
	}



	public void setVersion(Integer version) {
		this.version = version;
	}


	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getDescription());
	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final RappelTypeOT other = (RappelTypeOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getDescription(), other.getDescription());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }



	

}
